//
//  UIButton+extension.swift
//  WeiboSeven
//
//  Created by 刘刘 on 16/11/24.
//  Copyright © 2016年 刘刘. All rights reserved.
//

import UIKit

extension UIButton {
    convenience init(title: String?, fontSize: CGFloat = 13, color: UIColor = UIColor.darkGray, image: String? = nil, bgImage: String? = nil) {
        self.init()
        
        // 设置title
        if let title = title {
            self.setTitle(title, for: .normal)
            self.setTitleColor(color, for: .normal)
            self.titleLabel?.font = UIFont.systemFont(ofSize: fontSize)
        }
        // 设置图片
        if let image = image {
            self.setImage(UIImage(named: image), for: .normal)
            self.setImage(UIImage(named: "\(image)_highlighted"), for: .highlighted)
        }
        // 设置背景图片
        if let bgImage = bgImage {
            self.setBackgroundImage(UIImage(named: bgImage), for: .normal)
            self.setBackgroundImage(UIImage(named: "\(bgImage)_highlighted"), for: .highlighted)
        }
    }
}
